package com.example.news_demo.controller;

import com.example.news_demo.entity.Article;
import com.example.news_demo.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Type;
import java.util.List;

@Controller
@RequestMapping("/ContentView")
public class ContentViewController {

    @Autowired
    ArticleService articleService;

    @RequestMapping("/getOne")
    public String getOne(HttpServletRequest request , Model model){
        //获取id
        int id = Integer.parseInt(request.getParameter("id"));
        //获取文章信息
        Article article = articleService.getOneById(id);
        model.addAttribute("oneById",article);
        List<Article> correlateList = articleService.getCorrelation(id);
        model.addAttribute("correlateList",correlateList);
//        System.out.println(article.getId());
        return "news_view";
    }

   /* @RequestMapping("/getRandom")
    public String getRandom(){

    }*/
   @RequestMapping("/logView")
   public void viewLog(HttpServletRequest request){
       articleService.insertViewLog(request);
   }
}
